package net.joey.ognl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.opensymphony.xwork2.ognl.OgnlValueStack;
import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
import com.opensymphony.xwork2.util.CompoundRoot;
import com.opensymphony.xwork2.util.ValueStack;

import ognl.Ognl;
import ognl.OgnlContext;
import ognl.OgnlException;
import ognl.OgnlRuntime;

public class OgnlMain2 {

	/**
	 * @param args
	 * @throws OgnlException 
	 */
	public static void main(String[] args) throws OgnlException {
		// TODO Auto-generated method stub
		// Create root object    
//		OgnlValueStack valueStack= new OgnlValueStack(null, null, null, false);
//		ValueStack vs = new OgnlValueStack(null, null, null, false);
		CompoundRootAccessor cra = new CompoundRootAccessor();
		OgnlRuntime.setPropertyAccessor(CompoundRoot.class, cra);
		User user = new User();    
		user.setId(1);    
		user.setName("user1");    
        User user2 = new User();    
        user2.setId(2);    
        user2.setName("user2");    
        Department de1 = new Department();
        de1.setId(1);
        de1.setName("de1");
        CompoundRoot root = new CompoundRoot();
        System.out.println(root.getClass());
        root.add(user);
        root.add(de1);
        // Create context    
        OgnlContext context = new OgnlContext();    
        context.setRoot(root);
        System.out.println("aa");
        Ognl.setValue(Ognl.parseExpression("name"), context, root,"name1");
        Ognl.setValue(Ognl.parseExpression("desc"), context, root,"desc1");
        System.out.println(Ognl.getValue(Ognl.parseExpression("name"), context, root));  
        System.out.println("dd");
        System.out.println(StringUtils.join(root, "#"));
        

	}

}
